#include "BinarySearchTree.h"

void test1()
{
	BinarySearchTree::keyBSTree<int> b1;
	vector<int> v1({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });

	for (auto e : v1)
	{
		b1.insert(e);
	}
	b1.InOrder();

	for (auto e : v1)
	{
		b1.erase(e);
		b1.InOrder();
	}
}

void test2()
{
	BinarySearchTree::keyBSTree<int> b1;
	vector<int> v1({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });

	for (auto e : v1)
	{
		b1.insert(e);
	}
	b1.InOrder();

	cout << b1.find(3) << endl;
	cout << b1.find(1) << endl;
	cout << b1.find(4) << endl;
	cout << b1.find(7) << endl;
	cout << b1.find(99) << endl;
	cout << b1.find(100) << endl;

	cout << endl;

	cout << b1.findR(3) << endl;
	cout << b1.findR(1) << endl;
	cout << b1.findR(4) << endl;
	cout << b1.findR(7) << endl;
	cout << b1.findR(99) << endl;
	cout << b1.findR(100) << endl;
}

void test3()
{
	BinarySearchTree::keyBSTree<int> b1;
	vector<int> v1({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });
	for (auto e : v1)
	{
		b1.insert(e);
	}
	b1.InOrder();

	BinarySearchTree::keyBSTree<int> b2;
	vector<int> v2({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });
	for (auto e : v2)
	{
		b2.insertR(e);
	}
	b2.InOrder();
}

void test4()
{
	BinarySearchTree::keyBSTree<int> b1;
	vector<int> v1({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });
	for (auto e : v1)
	{
		b1.insert(e);
	}
	b1.InOrder();

	for (auto e : v1)
	{
		b1.erase(e);
		b1.InOrder();
	}

	BinarySearchTree::keyBSTree<int> b2;
	vector<int> v2({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });
	for (auto e : v2)
	{
		b2.insertR(e);
	}
	b2.InOrder();

	for (auto e : v2)
	{
		b2.eraseR(e);
		b2.InOrder();
	}
}

void test5()
{
	vector<int> v1({ 8, 3, 1, 10, 6, 4, 7, 14, 13 });
	vector<int> v2({ 9, 3, 22, 10, 6, 25, 7, 14, 12 });
	vector<int> v3({ 8, 77, 1, 125, 11, 4, 25, 14, 13 });

	BinarySearchTree::keyBSTree<int> b1;
	for (auto e : v1)
	{
		b1.insert(e);
	}
	b1.InOrder();

	BinarySearchTree::keyBSTree<int> b2;
	for (auto e : v2)
	{
		b2.insert(e);
	}
	b2.InOrder();

	BinarySearchTree::keyBSTree<int> b3;
	for (auto e : v3)
	{
		b3.insert(e);
	}
	b3.InOrder();

	BinarySearchTree::keyBSTree<int> b4(b1);
	b4.InOrder();
	BinarySearchTree::keyBSTree<int> b5(b2);
	b5.InOrder();
	BinarySearchTree::keyBSTree<int> b6(b3);
	b6.InOrder();

	b5 = b1;
	b6 = b1;

	cout << endl;

	b5.InOrder();
	b6.InOrder();
}

void test6()
{
	string s1[] = { "苹果", "香蕉", "雪梨","苹果", "苹果", "苹果", "雪梨", "雪梨" , "香蕉" };
	BinarySearchTree::kVBSTree<string, int> n1;

	for (auto& str : s1)
	{
		auto ret = n1.find(str);
		if (ret)
		{
			ret->_value++;
		}
		else
		{
			n1.insert(str, 1);
		}
	}
	n1.InOrder();
}

void test7()
{
	BinarySearchTree::kVBSTree<string, string> dict;
	dict.insert("hello", "你好");
	dict.insert("sort", "排序");
	dict.insert("merge", "归并");
	dict.insert("function", "函数");
	dict.insert("insert", "插入");
	dict.insert("erase", "删除");
	dict.insert("string", "字符串");
	dict.insert("array", "数组");

	string str;
	while (cin >> str)
	{
		auto ret = dict.find(str);
		if (ret)
		{
			cout << "对应中文：" << ret->_value << endl;
		}
		else
		{
			cout << "没有找到" << endl;
		}
	}
}

int main()
{
	//test1();
	//test2();
	//test3();
	//test4();
	//test5();

	//test6();
	test7();

	return 0;
}
